package com.hust.bridgecheck.controller.HomePage;

import com.hust.bridgecheck.entity.Notify;
import com.hust.bridgecheck.entity.User;
import com.hust.bridgecheck.service.Settings.NotifyService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class IndexController {
    @Autowired
    NotifyService notifyService;

    @GetMapping("/")
    public String home(Model model){
        //更加用户的UID和readed属性获取所有通知
        Session session = SecurityUtils.getSubject().getSession();
        User u = (User)session.getAttribute("user");
        Integer UID = u.getGroupID();//UID在session中获取暂时未启动
        List<Notify> notifylist = notifyService.getUserNotify(UID,0);
        model.addAttribute("notifylist",notifylist);
        model.addAttribute("listCount",notifylist.size());
        return "index";
    }
}
